import { $request } from '../../utils/request'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lists: [],
    lists_r: [],//右边子类,
    activeIndex:0,
    
  },
  getListData() {
    $request({ url: '/tag/search/list' }).then((res1) => {
      this.setData({
        lists: res1.data
      })
      console.log(res1.data)
      $request({ url: '/element/search/list?tagId=1'}).then((res2)=>{
      console.log(res2.data)
       this.setData({
      lists_r:res2.data,
      activeIndex: 0,
     
    })
      })
    }).catch(error=>{
      console.log(error)
    })
  },
  changeData(e) {//点击事件，接受传递，加载数据
    console.log(e.currentTarget.dataset)
    console.log('e.currentTarget.dataset.tagid',e.currentTarget.dataset.tagid)
    const index = e.currentTarget.dataset.index;
    $request({url:`/element/search/list?tagId=${e.currentTarget.dataset.tagid}`})
    .then((res)=>{
      this.setData({
        lists_r:res.data,
        activeIndex: index,
      })
      console.log(index)
      console.log(res.data)
    })
    .catch(catcherr => {
      console.error(catcherr);
    })
  },
  changePage(e) {
    const id = e.currentTarget.dataset.id
      const index = e.currentTarget.dataset.index;
    console.log(e)
    wx.navigateTo({
      url: `../city/city?id=${id}`,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({
      success: (res) => {
        that.setData({
          winHeight: res.windowHeight
        });
      }
    });
    that.getListData()
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

